package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DAO.ReportManagementDAO;

import com.et.mvc.JsonView;

/**
 * Servlet implementation class selectAssetWxServlet
 */
public class selectAssetWxServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public selectAssetWxServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

	    request.setCharacterEncoding("utf-8");        
		String assetNo = request.getParameter("assetNo");
		String name = request.getParameter("assetName");
		String department = request.getParameter("useDepartment");
		String level = request.getParameter("level");
        int start = Integer.parseInt(request.getParameter("start"));
        int limit = Integer.parseInt(request.getParameter("limit"));
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();	
		
		ReportManagementDAO getMSDAO = new ReportManagementDAO();
		@SuppressWarnings("unchecked")
		List getMSSelectList = null;
        Map<String,Object> map = new HashMap<String,Object>();
        
        
        if(assetNo.equals("") && name.equals("") && department.equals("") && level.equals(""))
        {
        	getMSSelectList = getMSDAO.getAllMS(start , limit);         	         	 
        }           
        else
        {
        	 getMSSelectList = getMSDAO.getMSByQuery(start,limit,assetNo,name,department,level);      	
        }
        map.put("total",getMSDAO.count);
        map.put("result",getMSSelectList);  
        out.print(new JsonView(map));
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
